package edu.sctu.liangyuxiang.day20150628;

import java.io.*;

/**
 * Created by user20 on 2015/6/28.
 */
public class IOUntil {
    public void judgePath(String path){
        File file = new File(path);
        if(!file.exists() && !file.isDirectory()){
            file.mkdir();
        }
    }


    public void serializableJson(String string,String path)throws Exception{
        judgePath(path);

        ObjectOutputStream json = new ObjectOutputStream(new FileOutputStream(path));
        json.writeObject(string);
        json.close();
    }

    public void serializableAppbean(Appbean string,String path)throws Exception{
        judgePath(path);

        ObjectOutputStream json = new ObjectOutputStream(new FileOutputStream(path));
        json.writeObject(string);
        json.close();
    }

    public Appbean readAppbean(String path)throws Exception{
        ObjectInputStream jsons = new ObjectInputStream(new FileInputStream(path));
        Appbean appbean = (Appbean)jsons.readObject();
        jsons.close();
        return appbean;
    }

}
